package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportCompany;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * created by wangjunfu on 2019-05-19 00:26:17
 */
@Repository
public class TransportCompanyDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportCompanyDao.class);

    public TransportCompany insert(final TransportCompany transportCompany) {
        insert("TransportCompany.insert", transportCompany);
        return transportCompany;
    }

    public Boolean updateInfoById(final TransportCompany transportCompany) {
        return update("TransportCompany.updateInfoById", transportCompany) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportCompany.updateInfoByQuery", query) > 0;
    }

    public TransportCompany selectById(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return queryForObject("TransportCompany.selectById", query);
    }

    public TransportCompany selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportCompany.selectByIdEnt", query);
    }

    public List<TransportCompany> selectByQuery(final Query query) {
        return queryForList("TransportCompany.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportCompany.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportCompany transportCompany = new TransportCompany();
        transportCompany.setDeleteFlag(1);
        transportCompany.setId(id);
        transportCompany.setEntId(entId);

        return update("TransportCompany.updateInfoById", transportCompany) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportCompany.deleteById", query) > 0;
    }

    //模糊搜索公司
    public List<Map<String, String>> selectSimilarCompany(final Query query) {
        List<Map<String, String>> map = queryForList("TransportCompany.selectSimilarCompany", query);
        return map;
    }
}